package com.speedcar.base.result;

import com.speedcar.base.i18n.ScI18nUtils;
import com.speedcar.base.model.ScResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ScDefaultResultWrapper implements ScResultWrapper {

    @Autowired
    private FlexibleResultWrapChecker wrapChecker;

    @Override
    public Object wrap(Object body) {
        return new ScResultJson(body);
    }

    @Override
    public Object wrapException(String code, String message, Object[] args) {
        return new ScResultJson(code, ScI18nUtils.get(message, args));
    }

    @Override
    public boolean supports(Object body) {
        // 如果对象可能是已包装的，则不进行包装
        return !wrapChecker.isLikelyWrapped(body);
    }
}
